import { ref } from 'vue'
import { ENUM_EXAMINE_APPROVE_STATUS } from '/@/api/examine/types'

export const moduleName = '审批管理'

// 搜索字段配置
export const searchFields = [
  {
    label: '类型',
    prop: 'type',
    component: 'select',
    placeholder: '请选择类型',
    options: [
      { label: '我发起的', value: '1' },
      { label: '我审核的', value: '2' },
    ],
  },
  {
    label: '状态',
    prop: 'status',
    component: 'select',
    placeholder: '请选择状态',
    options: [
      { label: '审核中', value: ENUM_EXAMINE_APPROVE_STATUS.审核中 },
      { label: '审核通过', value: ENUM_EXAMINE_APPROVE_STATUS.审核通过 },
      { label: '审核不通过', value: ENUM_EXAMINE_APPROVE_STATUS.审核不通过 },
      { label: '提交', value: ENUM_EXAMINE_APPROVE_STATUS.提交 },
    ],
  },
]

// 详情字段配置
export const detailFields = [
  {
    label: '审核内容',
    prop: 'content',
  },
  {
    label: '提交人',
    prop: 'user.name',
    formatter: (row: any) => row.user?.name || '-',
  },
  {
    label: '审核人',
    prop: 'reviewerUser.name',
    formatter: (row: any) => row.reviewerUser?.name || '-',
  },
  {
    label: '请假证明',
    prop: 'imageUrl',
    type: 'image',
    formatter: (row: any) => row.imageUrl || '-',
  },
  {
    label: '状态',
    prop: 'status',
    formatter: (row: any) => statusMap[row.status] || '-',
  },
  {
    label: '开始时间',
    prop: 'startTime',
  },
  {
    label: '结束时间',
    prop: 'endTime',
  },
  {
    label: '审核备注',
    prop: 'remark',
  },
]

// 审核表单字段配置
export const checkFormFields = [
  {
    label: '审核状态',
    prop: 'status',
    component: 'select',
    placeholder: '请选择审核状态',
    fullWidth: true,
    options: [
      { label: '审核通过', value: ENUM_EXAMINE_APPROVE_STATUS.审核通过 },
      { label: '审核不通过', value: ENUM_EXAMINE_APPROVE_STATUS.审核不通过 },
    ],
    rules: [{ required: true, message: '请选择审核状态', trigger: 'change' }],
  },
  {
    label: '审核备注',
    prop: 'remark',
    component: 'input',
    fullWidth: true,
    placeholder: '请输入审核备注',
    componentProps: {
      type: 'textarea',
      rows: 3,
    },
    rules: [{ required: true, message: '请输入审核备注', trigger: 'blur' }],
  },
]

// 表格列配置
export const tableColumns = ref<any[]>([
  {
    label: '审核内容',
    prop: 'content',
  },
  {
    label: '提交人',
    prop: 'user',
    formatter: (row: any) => row.user?.name || '-',
  },
  {
    label: '审核人',
    prop: 'reviewerUser',
    formatter: (row: any) => row.reviewerUser?.name || '-',
  },
  {
    label: '状态',
    prop: 'status',
    formatter: (row: any) => statusMap[row.status] || '-',
  },
  {
    label: '开始时间',
    prop: 'startTime',
  },
  {
    label: '结束时间',
    prop: 'endTime',
  },
  {
    label: '审核备注',
    prop: 'remark',
  },
  {
    label: '操作',
    prop: 'operation',
    fixed: 'right',
    width: 200,
  },
])

// 状态映射
export const statusMap = {
  [ENUM_EXAMINE_APPROVE_STATUS.审核中]: '审核中',
  [ENUM_EXAMINE_APPROVE_STATUS.审核通过]: '审核通过',
  [ENUM_EXAMINE_APPROVE_STATUS.审核不通过]: '审核不通过',
  [ENUM_EXAMINE_APPROVE_STATUS.提交]: '提交',
}
